/**
 * @fileOverview The "modetabs" plugin. 
 */
(function() {

   VED.plugins.add( 'modetabs', {
      // lang: 'en,ru', // %REMOVE_LINE_CORE%

      init: function( editor ) {
         
         var spaceId = editor.ui.spaceId( 'tabs' );
         
         function onClick( mode, el ) {
            el = new VED.dom.element( el );
            
            if ( el.hasClass( 'active' ) ) return false;
            
            var tabs = el.getParent().getChildren();
            
            for ( var i = 0, count = tabs.count(); i < count; i++ ) {
               var tab = tabs.getItem( i );
               if( tab.hasClass( 'active' ) ) tab.removeClass( 'active' );
            }
            
            el.addClass( 'active' );
            
            if ( editor.mode == 'wysiwyg' ) editor.fire( 'saveSnapshot' );
            // editor.getCommand( 'source' ).setState( VED.TRISTATE_DISABLED );
            editor.setMode( mode );
         }
         
         var onClickHanlder = VED.tools.addFunction( onClick );

         editor.on( 'uiSpace', function( event ) {
            if ( event.data.space == 'title' ) {
               var output = [
                  '<span id="' + spaceId + '_label" class="ved_modetabs">',
                     '<ul class="tabsheets">',
                        '<li id="" class="ved_modetab' + ( this.config.startupMode == 'wysiwyg' ? ' active' : '' ) + '" onclick="VED.tools.callFunction(' + onClickHanlder + ',\'wysiwyg\',this); return false;" role="tab">Дизайн</li>',
                        '<li id="" class="ved_modetab' + ( this.config.startupMode == 'source' ? ' active' : '' ) + '" onclick="VED.tools.callFunction(' + onClickHanlder + ',\'source\',this); return false;" role="tab">HTML</li>',
                     '</ul>',
                  '</span>'
               ];
               
               event.data.html += output.join( '' );
            }
         });
         
      }
   });

})();





